package sz.cn.aop;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;

public class TransactionAspect {
    private static final Logger log = LoggerFactory.getLogger(TransactionAspect.class);

    public void before(){
        log.info("自检");
        Random random = new Random();
        int num = random.nextInt(10);
        if (num < 5){
            log.info("检查正常");
        }else {
            throw new RuntimeException("出现异常");
        }
    }

    public void afterReturning(){
        log.info("打印成功");
    }


    public void afterThrowing(Throwable e){
        log.info("出现异常：" + e.getMessage());
    }
}
